home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Venus / window.h < prev   
Encoding:
C/C++ Source or Header  |  1994-07-26  |  3.4 KB  |  114 lines  |  [TEXT/ALFA]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *
  5.  *                                Simple Window Class
  6.  *        
  7.  *
  8.  ***********************************************************************
  9.  */
  10.  
  11. /*
  12.  *----------------------------------------------------------------------
  13.  *                            Service functions
  14.  */
  15.  
  16. class ScreenRect : public Rect
  17. {
  18. public:
  19.     ScreenRect(const Rect& rect)     { *this = *(ScreenRect *)▭ }
  20.     ScreenRect(const IMAGE& image);
  21.     ScreenRect(const rowcol& heightwidth);
  22.                                     // Create a rectangle of given height/width
  23.                                     // positioned at a given point
  24.     ScreenRect(const rowcol& origin, const rowcol& heightwidth);
  25.     ~ScreenRect(void) {}
  26.     ScreenRect& operator += (const int offset);
  27.     operator Rect * (void) { return this; }
  28.     void print(const char * title = "") const;
  29. };
  30.  
  31.                                     // Pascal String, this is just a type conversion
  32. class Pstr
  33. {
  34.     Str255 pas_string;
  35. public:
  36.     Pstr(const char * c_str);
  37.     ~Pstr(void) {}
  38.     operator unsigned char const * () { return pas_string; }
  39. };
  40.  
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *        A generic simple window that can be dragged around the screen
  45.  *                and closed by clicking a "go-away" button
  46.  * No other events are handled, redefine the event handler if necessary.
  47.  */
  48.  
  49. class ScreenWindow
  50. {
  51.     WindowPtr this_window;
  52.     
  53.     Boolean handle_mouse_down(const EventRecord& the_event);
  54.     virtual Boolean handle_key_down(const EventRecord& the_event);    // Handles key_down & auto_key events
  55.     virtual Boolean handle_null_event(const long event_time);
  56.     void drag(Point where) { DragWindow(this_window,where,&screenBits.bounds); }
  57.     void activate(const Boolean go_active);
  58.     void update(void);
  59.     virtual void draw(void) = 0;            // It is this function that really draws smth
  60.     
  61. protected:
  62.     WindowPtr our_window(void) const     { return this_window; }
  63.     
  64. public:
  65.     ScreenWindow(ScreenRect rect, const char * title);
  66.     ScreenWindow(const short resource_id);        // Create a window from a resource template
  67.     ~ScreenWindow(void);
  68.     void handle(void);
  69.     void refresh(void);
  70. };
  71.  
  72. /*
  73.  *----------------------------------------------------------------------
  74.  *            A simple window with an offscreen window buffer
  75.  */
  76.  
  77. class OffScreenWindow : public ScreenWindow
  78. {
  79.     GWorldPtr graf_world;                // (Offscreen) graphical world that contains the picture
  80.  
  81.     void activate_palette(void);        // Activate palette for the window
  82.     void draw(void);                    // Draw the offscreen buffer on screen
  83.  
  84. protected:
  85.     PixMapHandle pixmap;                // Pixmap for the offscreen world
  86.     int _height;                            // Dimensions of the pixmap (precomputed for
  87.     int _width;                            // easy reference
  88.     int _bytes_per_row;                    // Note, bytes_per_row >= width (and generally, not equal)
  89.     
  90. public:
  91.     OffScreenWindow(ScreenRect rect, const char * title, const short clut_id=0);
  92.     ~OffScreenWindow(void);
  93.  
  94.     PixMapHandle get_pixmap(void) const        { return pixmap; }
  95.         
  96.     ScreenRect q_bounds(void) const;    // Bounding rect of the grafworld
  97.     int height(void) const                    { return _height; }         
  98.     int width(void) const                    { return _width; }         
  99.     int bytes_per_row(void) const            { return _bytes_per_row; }         
  100.  
  101.     class SetOffscreenWorld
  102.     {
  103.         GrafPtr old_port;
  104.       public:
  105.                                           // Switch to an off-screen grafworld
  106.           SetOffscreenWorld(const OffScreenWindow& offscreen_window)     
  107.               { GetPort(&old_port); SetPort((GrafPtr)offscreen_window.graf_world); }
  108.                                         // Restore the original grafworld
  109.         ~SetOffscreenWorld(void) { SetPort(old_port); }
  110.     };
  111.     
  112.     
  113. };
  114.